package com.cg.design.graphicdesignpattern.builder;

/**
 * 声明了编写文档的方法的抽象类
 *
 * @program: LeetCode->Builder
 * @description: 声明了编写文档的方法的抽象类
 * @author: cg
 * @create: 2022-03-20 20:55
 **/
public abstract class Builder {

    private boolean initialized = false;

    public void makeTitle(String title) {
        if (!initialized) {
            buildTitle(title);
            initialized = true;
        }
    }

    public void makeString(String string) {
        if (initialized) {
            buildString(string);
        }
    }

    public void makeItems(String[] items) {
        if (initialized) {
            buildItems(items);
        }
    }

    public void close() {
        if (initialized) {
            buildDone();
        }
    }

    /**
     * 编写标题的抽象方法
     *
     * @param title
     */
    protected abstract void buildTitle(String title);

    /**
     * 编写字符串的抽象方法
     *
     * @param string
     */
    protected abstract void buildString(String string);

    /**
     * 编写条目的抽象方法
     *
     * @param items
     */
    protected abstract void buildItems(String[] items);

    /**
     * 关闭的抽象方法
     */
    protected abstract void buildDone();

}
